<!-- 创建优惠券 之 设置属性 -->
<template>
	<view>
		<u-form>
			<view class="set-coupon">
				<!-- 名称 -->
				<view class="model">
					<view class="name item">
						<view class="item-left">
							<text>券名称</text>
						</view>
						<view class="item-right">
							<u-form-item prop="name" :border-bottom="false">
								<u-input type="text" v-model="model.name" placeholder="输入优惠券名称,10字内" input-align="right" :clearable= 'false'></u-input>
							</u-form-item>
							<u-icon class="icon" name="arrow-right" size=15px color="#bcbcbc" />
						</view>
					</view>
				</view>
				
				<!-- 基础信息 -->
				<view class="model">
					<!-- 开始时间 -->
					<view class="beginDate item">
						<view class="item-left">
							<text>开始时间</text>
						</view>
						<view class="item-right" @click="beginDateShow = true">
							<u-form-item prop="beginDate" :border-bottom="false">
								<u-picker mode="time" v-model="beginDateShow" @confirm="dateConfirm($event,1)"></u-picker>
								<text v-if="model.beginDate">{{model.beginDate}}</text>
								<text class="tip" v-else>领券开始时间</text>
								<u-icon name="arrow-right" size=15px color="#bcbcbc"/>
							</u-form-item>
						</view>
					</view>
					<!-- 结束时间 -->
					<view class="endDate item">
						<view class="item-left">
							<text>结束时间</text>
						</view>
						<view class="item-right" @click="endDateShow = true">
							<u-form-item prop="endDate" :border-bottom="false">
								<u-picker mode="time" v-model="endDateShow" @confirm="dateConfirm($event,2)"></u-picker>
								<text v-if="model.endDate">{{model.endDate}}</text>
								<text class="tip" v-else>领券结束时间</text>
								<u-icon name="arrow-right" size=15px color="#bcbcbc"/>
							</u-form-item>
						</view>
					</view>
					<!-- 有效期 -->
					<view class="overdue item">
						<view class="item-left">
							<text>券有效期</text>
						</view>
						<view class="item-right">
							<u-form-item prop="overdue" :border-bottom="false">
								<u-input type="select" :select-open="overdueShow" v-model="model.overdue" placeholder="请选择有效期" input-align="right" @click="overdueShow = true"></u-input>
							</u-form-item>
							<u-action-sheet :list="overdueList" v-model="overdueShow" @click="selectCallback($event,1)"></u-action-sheet>
						</view>
					</view>
					<!-- 限领张数 -->
					<view class="limit item">
						<view class="item-left">
							<text>限领张数</text>
						</view>
						<view class="item-right">
							<count-num @numChange="limitChange"></count-num>
						</view>
					</view>
				</view>
				
				<!-- 店铺直减券补充信息 -->
				<view class="model" v-if="index == 0 && index2 == 0">
					<!-- 直减金额 -->
					<view class="lessMoney item">
						<view class="item-left">
							<text>直减金额</text>
						</view>
						<view class="item-right">
							<u-form-item prop="lessMoney" :border-bottom="false">
								<u-input type="text" v-model="model.lessMoney" placeholder="输入金额" input-align="right" :clearable= 'false'></u-input>
							</u-form-item>
							<text class="text">元</text>
						</view>
					</view>
					<!-- 发行张数 -->
					<view class="amount item"> 
						<view class="item-left">
							<text>发行张数</text>
						</view>
						<view class="item-right">
							<count-num @numChange="amountChange"></count-num>
						</view>
					</view>
				</view>
				
				<!-- 店铺满减券补充信息 -->
				<view class="model" v-if="index == 0 && index2 == 1">
					<!-- 满多少 -->
					<view class="reachMoney item">
						<view class="item-left">
							<text>满</text>
						</view>
						<view class="item-right">
							<u-form-item prop="reachMoney" :border-bottom="false">
								<u-input type="text" v-model="model.reachMoney" placeholder="输入金额" input-align="right" :clearable= 'false'></u-input>
							</u-form-item>
							<text class="text">元</text>
						</view>
					</view>
					<!-- 减多少 -->
					<view class="lessMoney item">
						<view class="item-left">
							<text>减</text>
						</view>
						<view class="item-right">
							<u-form-item prop="lessMoney" :border-bottom="false">
								<u-input type="text" v-model="model.lessMoney" placeholder="输入金额" input-align="right" :clearable= 'false'></u-input>
							</u-form-item>
							<text class="text">元</text>
						</view>
					</view>
					<!-- 发行张数 -->
					<view class="amount item"> 
						<view class="item-left">
							<text>发行张数</text>
						</view>
						<view class="item-right">
							<count-num @numChange="amountChange"></count-num>
						</view>
					</view>
				</view>
				
				<!-- 店铺折扣券补充信息 -->
				<view class="model" v-if="index == 0 && index2 == 2">
					<!-- 打折方式 -->
					<view class="discountSort item">
						<view class="item-left">
							<text>打折方式</text>
						</view>
						<view class="item-right">
							<u-form-item prop="discountSort" :border-bottom="false">
								<u-input type="select" :select-open="discountSortShow" v-model="model.discountSort" placeholder="请选择打折方式" input-align="right" @click="discountSortShow = true"></u-input>
							</u-form-item>
							<u-action-sheet :list="discountSortList" v-model="discountSortShow" @click="selectCallback($event,2)"></u-action-sheet>
						</view>
					</view>
					<!-- 条件 -->
					<view class="require item" v-if="model.discountSort == discountSortList[0].text">
						<view class="item-left">
							<text>条件</text>
						</view>
						<view class="item-right">
							<u-form-item prop="require" :border-bottom="false">
								<u-input type="text" v-model="model.require" placeholder="输入金额" input-align="right" :clearable= 'false'></u-input>
							</u-form-item>
							<text class="text">件</text>
						</view>
					</view>
					<!-- 折扣 -->
					<view class="discount item" v-if="model.discountSort">
						<view class="item-left">
							<text>折扣</text>
						</view>
						<view class="item-right">
							<u-form-item prop="discount" :border-bottom="false">
								<u-input type="text" v-model="model.discount" placeholder="输入金额" input-align="right" :clearable= 'false'></u-input>
							</u-form-item>
							<text class="text">件</text>
						</view>
					</view>
					<!-- 发行张数 -->
					<view class="amount item"> 
						<view class="item-left">
							<text>发行张数</text>
						</view>
						<view class="item-right">
							<count-num @numChange="amountChange"></count-num>
						</view>
					</view>
				</view>
			
				<!-- 商品券补充信息 -->
				<view class="model" v-if="index == 1">
					<!-- 选择商品 -->
					<view class="check-goods item" v-if="true">
						<view class="item-left">
							<text>选择商品</text>
						</view>
						<navigator url="../add-coupon/add-coupon" class="item-right">
							<text style="color: #2ba4f7;">添加</text>
						</navigator>
					</view>
					<!-- 商品信息 -->
					<view class="goods" v-else v-for="item in 4">
						<!-- 商品信息 -->
						<view class="goods-info">
							<view class="goods-picture">
								<image src="../../../../static/images/money.png" mode=""></image>
							</view>
							<view class="goods-right">
								<view class="goods-name">
									英飞特无线鼠标
								</view>
								<view class="goods-stock_price">
									<view class="goods-price">
										￥1
									</view>
									<view class="goods-stock">
										库存7
									</view>
								</view>
							</view>
						</view>
						<!-- 券面额 -->
						<view class="lessMoney item" v-if="index2 == 0">
							<view class="item-left">
								<text>券面额</text>
							</view>
							<view class="item-right">
								<u-form-item prop="lessMoney" :border-bottom="false">
									<u-input type="text" v-model="model.lessMoney" placeholder="输入金额" input-align="right" :clearable= 'false'></u-input>
								</u-form-item>
								<text class="text">元</text>
							</view>
						</view>
						<!-- 折扣 -->
						<view class="discount item" v-if="index2 == 1">
							<view class="item-left">
								<text>折扣</text>
							</view>
							<view class="item-right">
								<u-form-item prop="discount" :border-bottom="false">
									<u-input type="text" v-model="model.discount" placeholder="输入折扣" input-align="right" :clearable= 'false'></u-input>
								</u-form-item>
								<text class="text">折</text>
							</view>
						</view>
						<!-- 发行张数 -->
						<view class="amount item">
							<view class="item-left">
								<text>发行张数</text>
							</view>
							<view class="item-right">
								<count-num @numChange="amountChange"></count-num>
							</view>
						</view>
					</view>
					
				</view>
			</view>
		
			<view class="coupon-bottom">
				<view class="coupon-btn" @click="save()">
					<text>下一步</text>
				</view>
			</view>
		</u-form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index:0,							//index  ----  0为店铺券，1为商品券
				index2:0,							//index = 0, index2  -----  0为店铺直减券，1为店铺满减券，2为店铺折扣券
													//index = 1, index2  -----  0为商品直减券，1为商品折扣券
				model:{                             //优惠券数据
					
				},
				beginDateShow:false,				//是否展示开始时间弹框
				endDateShow:false,					//是否展示结束时间弹框
				overdueShow:false,					//是否展示有效期选择弹框
				overdueList:[{text: '领券有效期内'},{text: '3天'},{text: '7天'},{text: '15天'}],  //有效期选项列表
				discountSortShow:false,				//是否展示店铺折扣券打折方式选择弹框
				discountSortList:[{text: '条件折扣（买N件 打M折'},{text: '统一折扣'}],  //店铺折扣券打折方式选择列表
			};
		},
		onLoad(e) {
			this.index = e.index;
			this.index2 = e.index2;
			uni.setNavigationBarTitle({ title: e.title})  //不同券设置不同的页面标题
		},
		methods:{
			// 时间选择回调，e = 1开始时间，e = 2为结束时间
			dateConfirm(date,e) {
				let wen = date.year + '年' + date.month + '月' + date.day + '日';
				e == 1 ? this.model.beginDate = wen : this.model.endDate = wen
			},
			//select组件的回调，e = 1,券有效期    e = 2,打折方式
			selectCallback(index,e){
				uni.hideKeyboard();
				e == 1 ? this.model.overdue = this.overdueList[index].text : this.model.discountSort = this.discountSortList[index].text
			},
			//限领张数count-num组件返回
			limitChange(number){
				this.model.limit = number
			},
			//发行张数count组件返回
			amountChange(number){
				this.model.amont = number
			},
			//下一步
			save(){
				console.log(this.model);
			}
		}
	}
</script>

<style lang="scss" scoped>
.set-coupon{
	margin-bottom: 80rpx;
	.model{
		margin: 20rpx;
		padding: 0 40rpx;
		background-color: #fff;
		
		.item:first-child{
			border-top: none;
		}
		.item{
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 100rpx;
			border-top: 1px solid #e9e9e9;
			.item-left{
				font-weight: 700;
				font-size: 15px;
			}
			.item-right{
				display: flex;
				align-items: center;
				.tip{
					margin-right: 10rpx;
					color: #c0c4cc;
				}
				.icon{
					margin-left: 10rpx;
				}
				.text{
					margin-left: 20rpx;
					line-height: 100rpx;
				}
			}
		}
	
		.goods{
			padding-bottom: 20rpx;
			border-top: 1px solid #e9e9e9;
			.goods-info{
				display: flex;
				padding: 30rpx 0;
				.goods-picture{
					margin-right: 40rpx;
					width: 50px;
					height: 50px;
					image{
						width: 100%;
						height: 100%;
					}
				}
				.goods-right{
					.goods-stock_price{
						display: flex;
						margin-top: 10rpx;
						.goods-price{
							margin-right: 20rpx;
							font-weight: 700;
						}
						.goods-stock{
							color: #9e9e9e;
						}
					}
				}
			}
			.item{
				border-top: none;
				height: 80rpx;
			}
		}
	}
}

.coupon-bottom{
	position: fixed;
	bottom: 0;
	width: 100%;
	height: 80rpx;
	background-color: #fff;
	.coupon-btn{
		position: absolute;
		right: 40rpx;
		top: 10rpx;
		width: 200rpx;
		height: 60rpx;
		line-height: 60rpx;
		text-align: center;
		color:#fff;
		font-size: 16px;
		border-radius: 20rpx;
		background-color: #2ba4f7;
	}
}
</style>